package com.shioirikukuri.common.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private Integer code; // 状态码
	private String message; // 返回信息
	private T data; // 返回数据

	// 成功返回
	public static <T> Result<T> success(T data) {
		Result<T> result = new Result<>();
		result.setCode(0);
		result.setMessage("success");
		result.setData(data);
		return result;
	}

	// 失败返回
	public static <T> Result<T> error(Integer code, String message) {
		Result<T> result = new Result<>();
		result.setCode(code);
		result.setMessage(message);
		return result;
	}


}